import ReactNative from 'react-native'

var ToastAndroid = ReactNative.ToastAndroid;

class Toast {
  SHORT = ToastAndroid.SHORT;
  LONG = ToastAndroid.LONG;
  TOP = ToastAndroid.TOP;
  BOTTOM = ToastAndroid.BOTTOM;
  CENTER = ToastAndroid.CENTER;

  show(message, duration, gravity) {
    this.showWithGravity(message, duration, gravity);
  }

  showWithGravity(message, duration, gravity) {
    if (typeof message != 'string') {
      message = JSON.stringify(message, null, 2);
    }
    if (duration != this.LONG) duration = this.SHORT;

    if (gravity != this.TOP && gravity != this.CENTER) {
      gravity = this.BOTTOM;
    }

    ToastAndroid.showWithGravity(message, duration, gravity);
  }
}

export default new Toast